<!DOCTYPE html>
<html lang="en">
<head>
    <title>管理系统 - 管理中心</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- <meta ng-include="'head.html'"> -->
    <style type="text/css">
        .table>tbody>tr>td { height: 25px!important; line-height: 25px!important }
        .table .input-group-btn>.btn{ height:30px; margin-top:0px;}
        .titleHead { font-family: 宋体; font-size: 14px; font-weight: 400; margin-left: 15px }
        .mt20{ margin-top: 20px }
        .mt40{ margin-top: 40px }
        .pHead{ color:#19B5FE }
        .edit{ margin-right: 15px; color:#19B5FE; }
    </style>
    <link rel="stylesheet" type="text/css" href="../lib/css/footable.bootstrap.min.css">
    <script src="../lib/js/jquery.min.js" type="text/javascript"></script>
    <script src="../js/build.js" type="text/javascript"></script>
    <script src="../js/public.js" type="text/javascript"></script>
</head>
<body class="flat-blue">
<div class="app-container H100" ng-app="myApp" ng-controller="myCtrl">
<div class="row content-container H100">
<div ng-include="'menus.html'" onload="loadReady()"></div>
<div class="container-fluid H100 pb15">
<div class="side-body padding-top H100" id="main" style="padding-top:70px">
    <!------------------Main---------------->
    <div class="H100" style="width:99%; background-color:#fff; position:relative">
        <div class="titleHead">➢公司认证</div>
        <!--基本信息-->
        <div class="panel panel-default mt20">
            <div class="panel-heading pHead">
                申请列表
            </div>
            <div class="panel-body">
                <table class="table table-striped" style="padding-bottom: 20px"></table>
            </div>
        </div>

    </div>
    <!------------------End Main---------------------->
</div>  <!--End side-body-->
</div>  <!--End container-fluid-->
</div>  <!--End content-container-->
<div ng-include="'footer.html'"></div>
</div>  <!--End app-container-->


<script type="text/javascript" src="../lib/js/footable.min.js"></script>
<script language="javascript">
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        loadCtlBase($scope);

        $scope.data = [];
        $scope.cacheUser = {};
        var statusText = ['未处理', '已同意', '已拒绝'];

        function loadData(){
            ajaxData('get_apply_company_list', {}, function(rst){
                var data = rst.data;
                $scope.data = data; cout(data);
                loadTable();
            });
        }

        function loadTable(){
            $('.table').html("");
            var data = $scope.data;
            var cols = [{'name':'userName', 'title':'申请人'},
                {'name':'company', 'title':'认证公司'},
                {'name':'editUser', 'title':'当前责任人'},
                {'name':'createTime', 'title':'申请时间'},
                {'name':'status', 'title':'状态'},
                // {'name':'telephone', 'title':'联系方式'},
                {'name':'userAdmin', 'title':'经办人'},
                {'name':'operate', 'title':'操作'}
            ];
            //// 数据呈现
            var rows = data.map(function(d, i){
                $scope.cacheUser[d.userName] = i;
                return {
                    userName: "<a href='userInfo.html?u="+ d.userName +"'>" + d.userName + "</a>", 
                    company: d.company, editUser:d.editUser=='' ? '无' : d.editUser,
                    createTime: d.createTime, 
                    status: '<span style="color:red">' + statusText[d.status] + '</spqn>', 
                    userAdmin: d.userAdmin,
                    operate: d.status!=0 ? '无' : ('<span class="glyphicon glyphicon-ok edit pointer" title="同意" data-user="' + d.userName +'"></span>'
                        + '<span class="glyphicon glyphicon-remove-circle red del pointer" title="拒绝" data-user="'+ d.userName +'"></span>')
                };
            });
            // 加载表格
            $('.table').footable({
                "paging": { "enabled": true, 'size':10 },
                "filtering": { "enabled": false },
                "sorting": { "enabled": true },
                "columns": cols,
                "rows": rows
            });

            function preOperate(user){
                var line = $scope.data[$scope.cacheUser[user]];
                return line;
            }
            //// 添加编辑事件
            $('.table').on('click', '.edit', function(d){
                operate($(this).attr("data-user"), 1);
            })
            //// 添加编辑事件
            $('.table').on('click', '.del', function(d){
                operate($(this).attr("data-user"), 2);
            })

            function operate(user, _flag){
                var line = preOperate(user);
                if(!line) return; 
                ajaxData('set_apply_company', {'id':line.id, 'flag':_flag, 'userName':line.userName, 'company':line.company}, function(rst){
                    var data = rst.data;
                    if(data[0]==data[1] && data[1]==0){
                        line.status = _flag;
                        line.userAdmin = getCookie('username');
                        if(_flag==1)line.editUser = line.userName;
                    }else{
                        alert("操作失败，未知异常");
                    }
                    loadTable();
                });
            }
        }

        $scope.goCompany = function(company){
            window.location.href = "companyInfo.html?cp=" + escape(company);
        };



        loadData();
    });



    
    
    $(document).ready(function(){
        // $("#fullH").heiht();

        /*
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd', language:'zh-CN', autoclose:true, minView:"month"
        });
        */
    });


</script>

</body>
</html>
